package io.gitee.baicaixiaozhan.httpmessageconverter.kit;

/**
 * DESC:
 *
 * @author baicaixiaozhan
 * @since v1.0.0
 */
public class ReplaceKit {

    private ReplaceKit() {
        throw new IllegalAccessError();
    }

    public static String replace(CharSequence source, int startIndex, int endIndex, char delimiter) {
        String str = source.toString();
        int[] strCodePoints = str.codePoints().toArray();
        int strLength = strCodePoints.length;
        if ((startIndex > strLength) || (startIndex > endIndex)) {
            return str;
        }
        if (endIndex > strLength) {
            endIndex = strLength;
        }
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < strLength; i++) {
            if (i >= startIndex && i < endIndex) {
                builder.append(delimiter);
            } else {
                builder.append(new String(strCodePoints, i, 1));
            }
        }
        return builder.toString();
    }

}
